package com.wgl.yygh.api;

import com.wgl.model.user.Patient;
import com.wgl.yygh.result.Result;
import com.wgl.yygh.serivice.PatientService;
import com.wgl.yygh.util.AuthContextHolder;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author wgl
 * @version 1.0.0
 * @ClassName PatientApiController.java
 * @Description TODO
 * @createTime 2022年02月12日 10:27:00
 */
@RestController
@RequestMapping("/api/user/patient")
public class PatientApiController {
    @Resource
    private PatientService patientService;

    /**
    * @Author: Wgl
    * @Description: 根据用户id查询其对应的所有就诊人信息
    * @Date: 2022/2/12 10:45;
    * @param request: ;
    * @return: com.wgl.yygh.result.Result;
    */
    @GetMapping("/auth/findAll")
    public Result findAll(HttpServletRequest request){
        List<Patient> list = patientService.fandAllUserId(AuthContextHolder.getUserId(request));

        return Result.ok(list);
    }


    /**
    * @Author: Wgl
    * @Description:添加就诊人
    * @Date: 2022/2/12 14:46;
    * @param patient:
     * @param request: ;
    * @return: com.wgl.yygh.result.Result;
    */
    @PostMapping("/auth/save")
    private Result savePatient(@RequestBody Patient patient,HttpServletRequest request){
        Long userId = AuthContextHolder.getUserId(request);
        patient.setUserId(userId);
        patientService.save(patient);
        return Result.ok();
    }

    /**
    * @Author: Wgl
    * @Description: 根据就诊人id获取就诊人信息
    * @Date: 2022/2/12 14:52;
    * @param id: ;
    * @return: com.wgl.yygh.result.Result;
    */
    @GetMapping("auth/get/{id}")
    public Result getPatient(@PathVariable Long id){
        Patient patient = patientService.getPatientId(id);
        return Result.ok(patient);
    }


    /**
    * @Author: Wgl
    * @Description: 修改就诊人
    * @Date: 2022/2/12 14:52;
    * @param patient:
     * @param request: ;
    * @return: com.wgl.yygh.result.Result;
    */
    @PostMapping("auth/update")
    public Result updatePatient(@RequestBody Patient patient,HttpServletRequest request){
        Long userId = AuthContextHolder.getUserId(request);
        patient.setUserId(userId);
        patientService.updateById(patient);
        return Result.ok();
    }


   /**
   * @Author: Wgl
   * @Description: 删除就诊人信息
   * @Date: 2022/2/12 14:52;
   * @param id: ;
   * @return: com.wgl.yygh.result.Result;
   */
    @DeleteMapping("auth/remove/{id}")
    public Result removePatient(@PathVariable Long id){
         patientService.removeById(id);
        return Result.ok();
    }


    /**
    * @Author: Wgl
    * @Description: 根据就诊人id获取就诊人信息
    * @Date: 2022/2/13 22:49;
    * @param id: ;
    * @return: com.wgl.model.user.Patient;
    */
    @GetMapping("/inner/get/{id}")
    public Patient getPatientOrder(@PathVariable Long id){
        return patientService.getPatientId(id);
    }
}
